package cn.tedu.test.luban.starter.config;
import cn.tedu.test.luban.starter.bean.Bean01;
import cn.tedu.test.luban.starter.condition.OSCondition;
import cn.tedu.test.luban.starter.selector.MySelector;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.*;

@Configuration
@PropertySource("user.properties")
@ComponentScan(basePackages = {"cn.tedu.test.luban.starter.bean"})
//@Import(MyConfiguration02.class)
@Import(MySelector.class)
public class MyConfiguration01 {
    public MyConfiguration01() {
        System.out.println("当前myConfiguration01被容器加载");
    }
    @Bean
    //指定的类在当前环境存在则满足条件
    //@ConditionalOnClass(name = {"cn.tedu.test.luban.starter.bean.Bean01"})
    //指定的类在当前容器中是否存在bean对象,如果存在 则满足条件
    //@ConditionalOnBean(type = {"cn.tedu.test.luban.starter.bean.Bean02"})
    //判断当前环境 spring容器是否在一个web应用中运行 显然 条件是false
    //@ConditionalOnWebApplication
    //1 定义了key值 key值必须存在 存在则满足
    //@ConditionalOnProperty(prefix = "luban",name = "user.name")
    //2 定义了key值 也定义了havingValue 必须存在 且值必须等于liushoufu
    /*@ConditionalOnProperty(
            prefix = "luban",
            name = "user.name",
            havingValue = "liushoufu1")*/
    //3 定义了key 定义了指定值value 定义 不存在直接满足判断条件
    @ConditionalOnProperty(
            prefix = "luban",
            name = "user.name1",
            havingValue = "liushoufu",
            matchIfMissing = true)
    public Bean01 bean01(){
        return new Bean01();
    }
}
